package demo1;

public class ArrayDemo {
    public static void main(String[] args) {
        //创建Student类型的数组
        Student1[] arr = new Student1[3];
        //创建Student类的对象
        Student1 s1 = new Student1("黑旋风", 19);
        Student1 s2 = new Student1("半岛", 18);
        Student1 s3 = new Student1("猪脚", 20);
        //将学生对象存储到数组中
        arr[0] = s1;
        arr[1] = s2;
        arr[2] = s3;
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            //通过数组名和下标取出Student类的数组中的数据 arr[i]
            Student1 s = arr[i];
            //输出数据
            //System.out.println(s.getName()+"====="+s.getAge());
            System.out.println(s);//Student类已经复写了Object类的toString()函数直接输出
        }
    }
}
